| Conditions | 12 |
| Paths | 1152 |
| Total Lines | 44 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Complex classes like attributes.js ➔ getAll often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
| 1 | import { |
||
| 9 | export function getAll(str, json) { |
||
| 10 | str = Hooks.instance.trigger('beforeAbeAttributes', str, json) |
||
| 11 | |||
| 12 | //This regex analyzes all attributes of a Abe tag |
||
| 13 | var re = /\b([a-z][a-z0-9\-]*)\s*=\s*("([^"]+)"|'([^']+)'|(\S+))/ig |
||
| 14 | |||
| 15 | var attrs = { |
||
| 16 | autocomplete: null, |
||
| 17 | desc: '', |
||
| 18 | display: null, |
||
| 19 | editable: true, |
||
| 20 | key: '', |
||
| 21 | 'max-length': null, |
||
| 22 | 'min-length': 0, |
||
| 23 | order: 0, |
||
| 24 | prefill: false, |
||
| 25 | 'prefill-quantity': null, |
||
| 26 | reload: false, |
||
| 27 | required: false, |
||
| 28 | source: null, |
||
| 29 | tab: 'default', |
||
| 30 | type: 'text', |
||
| 31 | value: '', |
||
| 32 | file: '', |
||
| 33 | visible: true |
||
| 34 | } |
||
| 35 | |||
| 36 | for (var match; match = re.exec(str); ){ |
||
| 37 | attrs[match[1]] = match[3] || match[4] || match[5] |
||
| 38 | } |
||
| 39 | |||
| 40 | attrs.sourceString = attrs.source |
||
| 41 | attrs.source = (typeof attrs.source !== 'undefined' && attrs.source !== null && attrs.source !== '')? |
||
| 42 | ((typeof json['abe_source'] !== 'undefined' && json['abe_source'] !== null && json['abe_source'] !== '')? |
||
| 43 | json['abe_source'][attrs.key] : |
||
| 44 | null |
||
| 45 | ) : |
||
| 46 | null |
||
| 47 | attrs.editable = (typeof attrs.editable === 'undefined' || attrs.editable === null || attrs.editable === '' || attrs.editable === 'false') ? false : true |
||
| 48 | |||
| 49 | attrs = Hooks.instance.trigger('afterAbeAttributes', attrs, str, json) |
||
| 50 | |||
| 51 | return attrs |
||
| 52 | } |